package com.zx.sdk.model;


import androidx.annotation.NonNull;

import com.google.gson.annotations.SerializedName;
import com.zx.sdk.util.CollectionHelper;
import com.zx.sdk.util.LeagueMemberHelper;

import java.util.ArrayList;
import java.util.Iterator;

public class Position {

    SelfPosition selfPosition;
    @SerializedName("target")
    private ArrayList<AdInfo> targets;//目标广告信息
    @SerializedName("ground")
    private ArrayList<AdInfo> grounds;//兜底广告信息
    @SerializedName("bidding")
    private ArrayList<AdInfo> bidding;//兜底广告信息

    public ArrayList<AdInfo> getGrounds() {
        return cleanNotSupportLeague(grounds);
    }

    public void setGrounds(ArrayList<AdInfo> value) {
        this.grounds = value;
    }

    public ArrayList<AdInfo> getTargets() {
        // 移除当前不支持的联盟
        return cleanNotSupportLeague(targets);
    }

    public void setTargets(ArrayList<AdInfo> value) {
        this.targets = value;
    }

    public ArrayList<AdInfo> getBidding() {
        return cleanNotSupportLeague(bidding);

    }

    public Position setBidding(ArrayList<AdInfo> bidding) {
        this.bidding = bidding;
        return this;
    }

    public SelfPosition getSelfPosition() {
        return selfPosition;
    }

    /**
     * 移除不支持的联盟广告位
     */
    @NonNull
    public ArrayList<AdInfo> cleanNotSupportLeague(ArrayList<AdInfo> list) {
        if (CollectionHelper.isEmpty(list)) {
            return new ArrayList<>();
        }
        Iterator<AdInfo> iterator = list.iterator();
        while (iterator.hasNext()) {
            AdInfo next = iterator.next();
            if (!LeagueMemberHelper.isSupportLeague(next.getLeague())) {
                iterator.remove();
            }
        }
        return list;
    }
}
